package com.muqi.app.im.widget;

import com.muqi.app.im.ui.AddFriendsActivity;
import com.muqi.app.im.ui.GroupPickContactsActivity;
import com.muqi.app.qlearn.student.R;
import com.obsessive.all.zxing.CaptureActivity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

public class TabChatWindow extends PopupWindow implements OnClickListener {
	private View conentView;
	private Context mContext;
	
	@SuppressLint("InflateParams") @SuppressWarnings("deprecation")
	public TabChatWindow(final Activity context) {
		this.mContext = context;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		conentView = inflater.inflate(R.layout.popup_dialog_club, null);
		//int h = context.getWindowManager().getDefaultDisplay().getHeight();
		int w = context.getWindowManager().getDefaultDisplay().getWidth();
		this.setContentView(conentView);
		this.setWidth(w/3+110);
		this.setHeight(LayoutParams.WRAP_CONTENT);
		this.setFocusable(true);
		this.setOutsideTouchable(true);
		this.update();
		ColorDrawable dw = new ColorDrawable(0000000000);
		this.setBackgroundDrawable(dw);
		this.setAnimationStyle(R.style.AnimationPreview);
		LinearLayout findFriendsLayout = (LinearLayout) conentView.findViewById(R.id.pop_find_friends);
		LinearLayout qrScanLayout = (LinearLayout) conentView.findViewById(R.id.pop_qr_scan);
		LinearLayout nearbyLayout = (LinearLayout) conentView.findViewById(R.id.pop_nearby);
		findFriendsLayout.setOnClickListener(this);
		qrScanLayout.setOnClickListener(this);
		nearbyLayout.setOnClickListener(this);
	}

	/**   
	 * showPopupWidow
	 * @param parent
	 */
	public void showPopupWindow(View parent) {
		if (!this.isShowing()) {
			this.showAsDropDown(parent, 0 , 5);
		} else {
			this.dismiss();
		}
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent();
		switch (v.getId()) {
		case R.id.pop_find_friends:
			intent.setClass(mContext, AddFriendsActivity.class);
			mContext.startActivity(intent);
			break;
		case R.id.pop_qr_scan:
			intent.setClass(mContext, CaptureActivity.class);
			mContext.startActivity(intent);
			break;
		case R.id.pop_nearby:
			intent.setClass(mContext, GroupPickContactsActivity.class);
			intent.putExtra(GroupPickContactsActivity.PICKTYPE, "NewGroup");
			mContext.startActivity(intent);
			break;
		default:
			break;
		}
		TabChatWindow.this.dismiss();
	}
}
